package cn.firstsoft.modules.workflow.web;

import cn.firstsoft.firstframe.util.ContextUtils;
import cn.firstsoft.firstframe.util.ObjectComparator;
import cn.firstsoft.firstframe.util.ReflectUtil;
import cn.firstsoft.firstframe.util.StorageUtil;
import cn.firstsoft.modules.knowledge.service.logic.KnowledgeCatalogyManager;
import cn.firstsoft.modules.message.domain.Messages;
import cn.firstsoft.modules.message.service.logic.MessagesManager;
import cn.firstsoft.modules.workflow.WorkFlowUtil;
import cn.firstsoft.modules.workflow.adapter.ToArchiveAdapter;
import cn.firstsoft.modules.workflow.domain.Workflow;
import cn.firstsoft.modules.workflow.domain.WorkflowArchive;
import cn.firstsoft.modules.workflow.domain.WorkflowArchive.FlowToKnowledgeField;
import cn.firstsoft.modules.workflow.domain.WorkflowFile;
import cn.firstsoft.modules.workflow.domain.WorkflowFileinbox;
import cn.firstsoft.modules.workflow.domain.WorkflowFileprocess;
import cn.firstsoft.modules.workflow.domain.WorkflowFlowagent;
import cn.firstsoft.modules.workflow.domain.WorkflowFlowfield;
import cn.firstsoft.modules.workflow.domain.WorkflowFlowtype;
import cn.firstsoft.modules.workflow.domain.WorkflowReport;
import cn.firstsoft.modules.workflow.domain.WorkflowStep;
import cn.firstsoft.modules.workflow.domain.WorkflowWordtemplate;
import cn.firstsoft.modules.workflow.service.logic.ToArchive;
import cn.firstsoft.modules.workflow.service.logic.ToArchiveNew;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFileManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFileinboxManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFilelockManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFlowRightManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFlowfieldManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowFlowtypeManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowKnowledgeManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowReportManager;
import cn.firstsoft.modules.workflow.service.logic.WorkflowStepManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.sf.json.JSONArray;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;
import org.springside.core.commons.BaseManageController;
import org.springside.core.commons.BusinessException;
import org.springside.core.commons.PageSortModel;
import org.springside.core.utils.DateUtil;
import org.springside.core.utils.StrUtils;
import org.springside.modules.security.domain.Dept;
import org.springside.modules.security.domain.Dict;
import org.springside.modules.security.domain.User;
import org.springside.modules.security.domain.UserSession;
import org.springside.modules.security.service.logic.DeptManager;
import org.springside.modules.security.service.logic.DictManager;
import org.springside.modules.security.service.logic.SystemWorkhourManager;
import org.springside.modules.security.service.logic.UserAreaManager;
import org.springside.modules.security.service.logic.UserManager;


//20150622

public class WorkflowFileManagerController
  extends BaseManageController
{
  private WorkflowKnowledgeManager workflowKnowledgeManager;
  private WorkflowFlowRightManager workflowFlowRightManager;
  ToArchiveAdapter toArchiveAdapter;
  private WorkflowFileManager workflowFileManager;
  private MessagesManager messagesManager;
  private WorkflowStepManager workflowStepManager;
  private WorkflowFileinboxManager workflowFileinboxManager;
  private WorkflowFlowtypeManager workflowFlowtypeManager;
  private WorkflowManager workflowManager;
  private WorkflowFlowfieldManager workflowFlowfieldManager;
  private DeptManager deptManager;
  private UserManager userManager;
  private DictManager dictManager;
  private WorkflowReportManager workflowReportManager;
  private WorkflowFilelockManager workflowFilelockManager;
  private SystemWorkhourManager systemWorkhourManager;
  private KnowledgeCatalogyManager knowledgeCatalogyManager;
  private UserAreaManager userAreaManager;
  private static final String SUPERVISOR_VIEW = "redirect:/modules/workflow/workflowFile.do?method=";
  private static final String GOTOSTEP_VIEW = "/modules/workflow/workflowFile_step.jsp";
  private static final String GOTOMEMBER_VIEW = "/modules/workflow/workflowFile_member.jsp";
  private static final String GOTOFINISH_VIEW = "/modules/workflow/workflowFile_finish.jsp";
  private static final String FILEREPORT_VIEW = "/modules/workflow/workflowFile_report.jsp";
  private static final String REPORTQUERY_VIEW = "/modules/workflow/workflowFile_reportquery.jsp";
  private static final String REPORTLIST_VIEW = "/modules/workflow/workflowFile_reportlist.jsp";
  private static final String SUPERVISORLIST_VIEW = "/modules/workflow/workflowFile_supervisor.jsp";
  private static final String DRAFT_VIEW = "/modules/workflow/workflow_draft.jsp";
  private static final String REPORT_VIEW = "/modules/workflow/workflow_report.jsp";
  private static final String AGENT_VIEW = "/modules/workflow/workflow_agent.jsp";
  private static final String AGENT2ME_VIEW = "/modules/workflow/workflow_agent2me.jsp";
  private static final String AGENTOTHER_VIEW = "/modules/workflow/workflow_agent_other.jsp";
  private static final String SHOWFLOW_VIEW = "/modules/workflow/workflow_show.jsp";
  private static final String WORDPRINT_VIEW = "/modules/workflow/workflowFile_wordprint.jsp";
  
  public void setWorkflowFlowRightManager(WorkflowFlowRightManager workflowFlowRightManager)
  {
    this.workflowFlowRightManager = workflowFlowRightManager;
  }
  
  public void setToArchiveAdapter(ToArchiveAdapter toArchiveAdapter)
  {
    this.toArchiveAdapter = toArchiveAdapter;
  }
  
  public void setWorkflowFileManager(WorkflowFileManager workflowFileManager)
  {
    this.workflowFileManager = workflowFileManager;
  }
  
  public void setMessagesManager(MessagesManager messagesManager)
  {
    this.messagesManager = messagesManager;
  }
  
  public void setWorkflowStepManager(WorkflowStepManager workflowStepManager)
  {
    this.workflowStepManager = workflowStepManager;
  }
  
  public void setWorkflowFileinboxManager(WorkflowFileinboxManager workflowFileinboxManager)
  {
    this.workflowFileinboxManager = workflowFileinboxManager;
  }
  
  public void setWorkflowFlowtypeManager(WorkflowFlowtypeManager workflowFlowtypeManager)
  {
    this.workflowFlowtypeManager = workflowFlowtypeManager;
  }
  
  public void setWorkflowManager(WorkflowManager workflowManager)
  {
    this.workflowManager = workflowManager;
  }
  
  public void setWorkflowFlowfieldManager(WorkflowFlowfieldManager workflowFlowfieldManager)
  {
    this.workflowFlowfieldManager = workflowFlowfieldManager;
  }
  
  public void setDeptManager(DeptManager deptManager)
  {
    this.deptManager = deptManager;
  }
  
  public void setUserManager(UserManager userManager)
  {
    this.userManager = userManager;
  }
  
  public void setDictManager(DictManager dictManager)
  {
    this.dictManager = dictManager;
  }
  
  public void setWorkflowReportManager(WorkflowReportManager workflowReportManager)
  {
    this.workflowReportManager = workflowReportManager;
  }
  
  public void setWorkflowFilelockManager(WorkflowFilelockManager workflowFilelockManager)
  {
    this.workflowFilelockManager = workflowFilelockManager;
  }
  
  public void setSystemWorkhourManager(SystemWorkhourManager systemWorkhourManager)
  {
    this.systemWorkhourManager = systemWorkhourManager;
  }
  
  public void setKnowledgeCatalogyManager(KnowledgeCatalogyManager knowledgeCatalogyManager)
  {
    this.knowledgeCatalogyManager = knowledgeCatalogyManager;
  }
  
  public void setUserAreaManager(UserAreaManager userAreaManager)
  {
    this.userAreaManager = userAreaManager;
  }
  
  public WorkflowFileManagerController()
  {
    this.listView = "/modules/workflow/workflowFile_list.jsp";
    this.editView = "/modules/workflow/workflowFile_edit.jsp";
    this.showView = "/modules/workflow/workflowFile_show.jsp";
    this.successView = "redirect:/modules/workflow/workflowFile.do";
  }
  
  protected void onList(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    createPermException(request, "设置中心->工作流->流程编辑", null);
    
    onQuery(request, response, mav);
  }
  
  protected void onQuery(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    map.put("deptId_i_eq", String.valueOf(user.getUc()));
    PageSortModel psm = new PageSortModel(request, "ec");
    List<WorkflowFile> workflowFiles = this.workflowFileManager
      .findWorkflowFileByPage(map, psm);
    mav.addObject("workflowFiles", workflowFiles);
  }
  
  public ModelAndView gotostep(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_step.jsp");
    



    Integer id = new Integer(request.getParameter("id"));
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
    UserSession userSession = getUserSession(request);
    if ((!this.workflowManager.getIsSupervisor(workflowFile.getWorkflow().getId(), userSession)) || 
      (2 != workflowFile.getFlowFlag().intValue())) {
      createPermException(request, "协同审批->文件监控->重定位", null);
    }
    mav.addAllObjects(referenceData(request));
    
    mav.addObject("sentStatusEnum", 
      cn.firstsoft.modules.workflow.Constants.sentStatusEnum());
    


    mav.addObject("workflowFile", workflowFile);
    






    List steps = this.workflowStepManager.findWorkflowStepByFlowId(workflowFile.getWorkflow().getId());
    Map<String, String> stepOrderMap = new LinkedHashMap();
    stepOrderMap.put("posy", "asc");
    stepOrderMap.put("posx", "asc");
    Collections.sort(steps, ObjectComparator.instance(stepOrderMap));
    
    mav.addObject("workflowSteps", steps);
    














    mav.addObject("currentFileinboxes", 
      this.workflowFileinboxManager.findCurrentFileinbox(id));
    
    return mav;
  }
  
  public ModelAndView reportquery(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_reportquery.jsp");
    
    Integer flowId = new Integer(request.getParameter("flowId"));
    
    Workflow workflow = this.workflowManager.getWorkflow(flowId);
    
    mav.addObject("workflow", workflow);
    
    mav
      .addObject("workflowFlowfields", 
      this.workflowFlowfieldManager
      .findAllWorkflowFlowfieldByFlwotypeId(workflow.getFlowtypeId()));
    

    mav.addObject("workflowvers", this.workflowManager
      .findWorkflowVer(workflow.getParentId()));
    
    mav.addObject("priorityMap", org.springside.core.Constants.WORKFLOW_PRIORITY_MAP);
    
    return mav;
  }
  
  public ModelAndView reportPrint(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_report.jsp");
    
    return mav;
  }
  
  public ModelAndView reportExcel(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    UserSession user = getUserSession(request);
    


    Integer id = new Integer(request.getParameter("id"));
    
    WorkflowReport workflowReport = this.workflowReportManager
      .getWorkflowReport(new Integer(id.intValue()));
    


    Integer flowId = new Integer(request.getParameter("flowId"));
    
    Workflow workflow = this.workflowManager.getWorkflow(flowId);
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    





    boolean haveRight = false;
    if ((workflow.getSupervisors() != null) && 
      (!"".equals(workflow.getSupervisors().trim())))
    {
      String supervisors = workflow.getSupervisors();
      supervisors = supervisors.replaceAll(" ", "");
      String[] observer = supervisors.split(",");
      for (int i = 0; i < observer.length; i++) {
        if (String.valueOf(user.getId()).equals(observer[i])) {
          haveRight = true;
        }
      }
    }
    if ((workflow.getObservers() != null) && 
      (!"".equals(workflow.getObservers().trim())))
    {
      String observers = workflow.getObservers();
      observers = observers.replaceAll(" ", "");
      String[] observer = observers.split(",");
      for (int i = 0; i < observer.length; i++) {
        if (String.valueOf(user.getId()).equals(observer[i])) {
          haveRight = true;
        }
      }
    }
    boolean superRight = false;
    if ((workflow.getSuperobservers() != null) && 
      (!"".equals(workflow.getSuperobservers().trim())))
    {
      String superObservers = workflow.getSuperobservers();
      superObservers = superObservers.replaceAll(" ", "");
      String[] superObserver = superObservers.split(",");
      for (int i = 0; i < superObserver.length; i++) {
        if (String.valueOf(user.getId()).equals(superObserver[i])) {
          superRight = true;
        }
      }
    }
    if ((haveRight) && (!superRight))
    {
      String deptId = (String)map.get("deptId");
      if ((deptId == null) || ("".equals(deptId))) {
        deptId = String.valueOf(user.getDeptId());
      }
      String longCode = user.getDeptCode();
      if (!deptId.equals(String.valueOf(user.getDeptId())))
      {
        Dept dept = this.deptManager.getDept(new Integer(deptId));
        if (dept.getDeptCode().startsWith(user.getDeptCode())) {
          longCode = dept.getDeptCode();
        }
      }
      String isdept = (String)map.get("isdept");
      if ("1".equals(isdept)) {
        map.put("deptXXdeptCode_s_likeleft", longCode);
      } else {
        map.put("deptXXdeptCode_s_eq", longCode);
      }
      String userId = (String)map.get("userId");
      if ((userId != null) && (!"".equals(userId)))
      {
        User user1 = this.userManager.getUser(new Integer(userId));
        if (user1.getDept().getDeptCode().startsWith(longCode)) {
          map.put("userXXid_i_eq", userId);
        }
      }
    }
    else if (superRight)
    {
      String deptId = (String)map.get("deptId");
      if ((deptId == null) || ("".equals(deptId)))
      {
        deptId = String.valueOf(workflow.getDept().getId());
      }
      else
      {
        Dept dept = this.deptManager.getDept(new Integer(deptId));
        String longCode = dept.getDeptCode();
        String isdept = (String)map.get("isdept");
        if ("1".equals(isdept)) {
          map.put("deptXXdeptCode_s_likeleft", longCode);
        } else {
          map.put("deptXXdeptCode_s_eq", longCode);
        }
      }
      String userId = (String)map.get("userId");
      if ((userId != null) && (!"".equals(userId))) {
        map.put("userXXid_i_eq", userId);
      }
    }
    else
    {
      map.put("userXXid_i_eq", String.valueOf(user.getId()));
    }
    map.put("flowFlag_i_ne", "0");
    

    map.put("flowPid_i_eq", String.valueOf(workflow.getParentId()));
    










    Map sortMap = new LinkedHashMap();
    
    String report_sort = workflowReport.getReportSort();
    if ((report_sort != null) && (!"".equals(report_sort)))
    {
      String[] report_sorts = report_sort.split("/");
      for (int i = 0; i < report_sorts.length; i++)
      {
        int p1 = report_sorts[i].indexOf(" ");
        String fieldName = report_sorts[i].substring(0, p1);
        String order = report_sorts[i].substring(p1 + 1);
        
        String field = this.workflowFileManager.getFieldByName(
          workflow.getFlowtypeId(), fieldName);
        if ((field != null) && (!"".equals(field))) {
          sortMap.put(field, order);
        }
      }
    }
    int pages = 0;
    
    String reportResult = this.workflowFileManager.getWorkflowReportContent(
      workflowReport, map, sortMap, Integer.valueOf(pages), workflow.getFlowtypeId(), 
      "print", this.userManager.getUser(user.getId()));
    if ((reportResult != null) && (!"".equals(reportResult.trim())))
    {
      response.setContentType("application/vnd.ms-excel");
      

      response.setHeader("Content-Disposition", "attachment; filename=" + 
        new String(workflowReport.getName().getBytes("GBK"), 
        "ISO-8859-1") + ".xls");
      
      StorageUtil.download(reportResult.getBytes(org.springside.core.Constants.OS_CHARSET), response.getOutputStream());
    }
    return null;
  }
  
  public ModelAndView gotomember(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_member.jsp");
    
    Integer id = new Integer(request.getParameter("id"));
    






    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
    

    UserSession userSession = getUserSession(request);
    if ((!this.workflowManager.getIsSupervisor(workflowFile.getWorkflow().getId(), userSession)) || 
      (2 != workflowFile.getFlowFlag().intValue())) {
      createPermException(request, "协同审批->文件监控->重定位", null);
    }
    Integer nextStepId = new Integer(request.getParameter("nextStepId"));
    WorkflowStep nextStep = this.workflowStepManager.getWorkflowStep(nextStepId);
    if (workflowFile.getWorkflow().getId().intValue() != nextStep.getFlowId().intValue()) {
      createPermException(request, "协同审批->文件监控->重定位", null);
    }
    mav.addObject("workflowFile", workflowFile);
    if ((workflowFile.getFlowFlag() != null) && 
      (workflowFile.getFlowFlag().intValue() == 1))
    {
      saveMessage(request, 
        getMessage(request, "workflowController_label3", "文件监控员文件已经结束，不能执行重定向！"));
      
      String viewId = request.getParameter("viewId");
      mav
        .setViewName("/modules/workflow/workflowFile.do?method=supervisorFinish&ec_s_submitdate=desc&isViewed=yes&viewId=" + 
        viewId);
      return mav;
    }
    mav.addObject("nextStep", nextStep);
    
    mav.addObject("nextStepUserMap", this.workflowStepManager
      .getMembers(nextStep, workflowFile));
    
    mav.addObject("controllStepId", "0");
    
    mav.addObject("isspecial", "0");
    
    String parentStepId = request.getParameter("parentStepId");
    mav.addObject("parentStepId", parentStepId);
    
    return mav;
  }
  
  public ModelAndView gotofinish(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_finish.jsp");
    
    Integer id = new Integer(request.getParameter("id"));
    WorkflowFile workflowFileTemp = this.workflowFileManager.getWorkflowFile(id);
    
    UserSession userSession = getUserSession(request);
    if ((!this.workflowManager.getIsSupervisor(workflowFileTemp.getWorkflow().getId(), userSession)) || 
      (2 != workflowFileTemp.getFlowFlag().intValue())) {
      createPermException(request, "协同审批->文件监控->重定位", null);
    }
    Map map = WebUtils.getParametersStartingWith(request, "nextstep_");
    
    String leaveword = request.getParameter("leaveword");
    if ((workflowFileTemp.getFlowFlag() != null) && 
      (workflowFileTemp.getFlowFlag().intValue() == 1))
    {
      saveMessage(request, 
        getMessage(request, "workflowController_label3", "文件监控员文件已经结束，不能执行重定向！"));
      
      String viewId = request.getParameter("viewId");
      mav
        .setViewName("/modules/workflow/workflowFile.do?method=supervisorFinish&ec_s_submitdate=desc&isViewed=yes&viewId=" + 
        viewId);
      return mav;
    }
    String rePositionReason = request.getParameter("rePositionReason");
    
    this.workflowFileinboxManager.saveGotoStep(id, map, leaveword, userSession, 
      rePositionReason);
    
    String stepId = (String)map.get("id");
    WorkflowStep workflowStep = this.workflowStepManager
      .getWorkflowStep(new Integer(stepId));
    if (workflowStep.getSteptypeId().intValue() == 8)
    {
      WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
      
      this.workflowFileinboxManager.archive(
        (WorkflowFileinbox)workflowFile.getWorkflowFileinboxes().iterator().next());
    }
    mav.addObject("currentFileinboxes", 
      this.workflowFileinboxManager.findCurrentFileinbox(id));
    
    mav.addObject("workflowFileprocesses", 
      this.workflowFileinboxManager.findWorkflowFileprocess(id));
    
    mav.addObject("processStatusEnum", 
      cn.firstsoft.modules.workflow.Constants.processStatusEnum());
    
    mav.addObject("sentStatusEnum", 
      cn.firstsoft.modules.workflow.Constants.sentStatusEnum());
    
    saveMessage(request, this.workflowFileinboxManager.getMessage());
    
    return mav;
  }
  
  public ModelAndView supervisor(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    return supervisor1(request, response, "2");
  }
  
  public ModelAndView supervisorDraft(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    return supervisor1(request, response, "0");
  }
  
  public ModelAndView supervisorFinish(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    return supervisor1(request, response, "1,5");
  }
  
  public ModelAndView supervisor1(HttpServletRequest request, HttpServletResponse response, String flowFlag)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_supervisor.jsp");
    
    mav.addAllObjects(referenceData(request));
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    
    map.put("flowFlag_i_in", flowFlag);
    if (StringUtils.isNotBlank(request.getParameter("deptIds")))
    {
      map.remove("deptXXname_s_like");
      map.put("deptXXid_i_eq", Integer.valueOf(request.getParameter("deptIds")));
    }
    if (StringUtils.isNotBlank(request.getParameter("flowIds")))
    {
      map.remove("workflowXXname_s_like");
      map.put("workflowXXid_i_eq", request.getParameter("flowIds"));
    }
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    













    map.put("workflowXXsupervisors_s_like", " " + 
      String.valueOf(user.getId()) + " ");
    
    PageSortModel psm = new PageSortModel(request, "ec");
    


    List<WorkflowFile> workflowFileList = null;
    if ((StringUtils.isNotEmpty(request.getParameter("ec_ev"))) && (StringUtils.isNotEmpty("ec_eti")) && (request.getParameter("ec_ev").equals("xls")) && (request.getParameter("ec_eti").equals("ec")))
    {
      psm.setPageSize(2000);
      psm.setPageNo(1);
      workflowFileList = this.workflowFileManager.findWorkflowFileByPage(map, psm);
    }
    else
    {
      workflowFileList = this.workflowFileManager.findWorkflowFileByPage(map, psm);
    }
    mav.addObject("workflowFiles", workflowFileList);
    















    String result = null;
    int index = 0;
    Map workflowFileMap = new HashMap();
    for (WorkflowFile workflowFile : workflowFileList)
    {
      result = this.workflowFileinboxManager.getStepUserString(
        workflowFile.getId().toString());
      index = result.indexOf("!");
      result = result.substring(index + 1);
      workflowFile.setStepName(result);
      result = result.replaceAll("<br>", "");
      








      result = result.replaceAll("<.*?>(.*?)</.*?>", "$1");
      
      workflowFileMap.put(workflowFile.getId(), result);
    }
    mav.addObject("workflowFileMap", workflowFileMap);
    
    mav.addObject("priorityMap", org.springside.core.Constants.WORKFLOW_PRIORITY_MAP);
    
    return mav;
  }
  
  public ModelAndView observerUnfinish(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    return observer(request, response, "2");
  }
  
  public ModelAndView observerFinish(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    return observer(request, response, "1");
  }
  
  public ModelAndView observer(HttpServletRequest request, HttpServletResponse response, String flowFlag)
    throws Exception
  {
    ModelAndView mav = new ModelAndView(this.listView);
    
    mav.addAllObjects(referenceData(request));
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    if ("1".equals(flowFlag)) {
      map.put("flowFlag_i_in", "1,5");
    } else {
      map.put("flowFlag_i_notin", "1,5");
    }
    if (StringUtils.isNotBlank(request.getParameter("deptIds")))
    {
      map.remove("deptXXdeptName_s_like");
      map.put("deptXXid_i_eq", request.getParameter("deptIds"));
    }
    if (StringUtils.isNotBlank(request.getParameter("flowIds")))
    {
      map.remove("workflowXXname_s_like");
      map.put("workflowXXid_i_eq", request.getParameter("flowIds"));
    }
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    













    map.put("workflowXXobservers_s_like", " " + 
      String.valueOf(user.getId()) + " ");
    














    map.put("deptXXdeptCode_s_likeleft", user.getDeptCode());
    
















    map.put("workflowXXsuperobservers_s_like", " " + 
      String.valueOf(user.getId()) + " ");
    PageSortModel psm = new PageSortModel(request, "ec");
    List workflowFiles = this.workflowFileManager
      .findWorkflowFileByHQL(map, psm);
    







    mav.addObject("workflowFiles", workflowFiles);
    mav.addObject("priorityMap", org.springside.core.Constants.WORKFLOW_PRIORITY_MAP);
    
    return mav;
  }
  
  protected void onEdit(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    mav.addObject("workflowFile", this.workflowFileManager.getWorkflowFile(id));
  }
  
  protected void onShow(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    Integer id = null;
    String fid = request.getParameter("id");
    String isRelation = request.getParameter("isrelation");
    String webIMIsIframe = request.getParameter("webIMIsIframe");
    mav.addObject("webIMIsIframe", webIMIsIframe);
    if ((isRelation == null) || (!"true".equals(isRelation))) {
      id = new Integer(fid);
    } else {
      id = Integer.valueOf(StrUtils.getDesString(fid));
    }
    request.setAttribute("inboxId", id);
    









    Integer fileinboxId = null;
    Integer fromId = null;
    String lastAction = "";
    String curId = "";
    Integer curfileId = null;
    try
    {
      fileinboxId = new Integer(request.getParameter("fileinboxId"));
    }
    catch (Exception e)
    {
      System.out.println(e.getMessage());
    }
    try
    {
      lastAction = request.getParameter("lastAction").trim();
    }
    catch (Exception localException1) {}
    try
    {
      curfileId = new Integer(request.getParameter("curId"));
    }
    catch (Exception localException2) {}
    UserSession userSession = getUserSession(request);
    WorkflowFile wf = this.workflowFileManager.getWorkflowFile(id);
    if (wf == null) {
      createPermException(request, "协同审批->公文->显示", null);
    }
    mav.addObject("knowledgesList", this.workflowKnowledgeManager.getWorkflowKnowledgeList(wf.getWorkflow().getId()));
    if (("toArchive".equals(lastAction)) || (fileinboxId == null))
    {
      if (curfileId == null)
      {
        if ((!this.workflowManager.getIsObservers(wf.getWorkflow().getId(), userSession)) && 
          (!this.workflowManager.getIsSupervisor(wf.getWorkflow().getId(), userSession)) && 
          (!this.workflowFileinboxManager.getIsWorkflowFileUser(userSession, String.valueOf(id)))) {
          if (!this.workflowFileManager.isArchiveMan(wf.getWorkflow().getParentId(), userSession)) {
            if (!this.workflowFlowRightManager.getWorkflowPerm(wf.getWorkflow().getId(), userSession.getId())) {
              createPermException(request, "协同审批->公文->显示", null);
            }
          }
        }
      }
      else if (((isRelation == null) || (!"true".equals(isRelation))) && 
        (!this.workflowManager.getIsObservers(wf.getWorkflow().getId(), userSession)) && 
        (!this.workflowManager.getIsSupervisor(wf.getWorkflow().getId(), userSession)) && 
        (!this.workflowFileinboxManager.getIsWorkflowFileUser(userSession, String.valueOf(id)))) {
        if ((!this.workflowFileManager.isArchiveMan(wf.getWorkflow().getParentId(), userSession)) && 
          (!this.workflowManager.getIsObserverRelationFile(wf.getWorkflow().getId(), id, curfileId, userSession)) && 
          (!this.workflowFileManager.getIsArchiveManRelFile(curfileId, id, userSession))) {
          createPermException(request, "协同审批->公文->显示", null);
        }
      }
    }
    else if ((!this.workflowManager.getIsObservers(wf.getWorkflow().getId(), userSession)) && 
      (!this.workflowManager.getIsSupervisor(wf.getWorkflow().getId(), userSession)) && 
      (!this.workflowFileinboxManager.getIsWorkflowFileUser(userSession, String.valueOf(id))) && 
      (!this.workflowFileManager.isRelationFile(fileinboxId, id, userSession))) {
      if (!this.workflowFileManager.isArchiveMan(wf.getWorkflow().getParentId(), userSession)) {
        createPermException(request, "协同审批->公文->显示", null);
      }
    }
    Map map = new HashMap();
    map.put("id_i_eq", String.valueOf(id));
    List workflowFileList = this.workflowFileManager.findWorkflowFile(map);
    if (workflowFileList.size() > 0)
    {
      WorkflowFile workflowFile = (WorkflowFile)workflowFileList.get(0);
      











      mav.addObject("wordprintAttachs", this.workflowFileManager.showWordPrintAttach(request, workflowFile));
      

      WorkFlowUtil.removeEmptyFile(workflowFile);
      
      this.workflowFileinboxManager.convertWorkflowFile(workflowFile);
      if ("".equals(this.workflowFlowtypeManager
        .getWorkflowTemplate(workflowFile, ""))) {
        saveMessage(request, 
        
          getMessage(request, "WorkflowFileManagerController_label6", "模板文件不存在，请联系系统管理员！"));
      }
      String content = this.workflowFlowtypeManager
        .getWorkflowTemplateContent(workflowFile, "");
      
      Pattern pattern = Pattern.compile("(<textarea.*?>)(.*?)(</textarea>)", 32);
      Matcher matcher = pattern.matcher(content);
      StringBuffer buffer = new StringBuffer();
      while (matcher.find()) {
        matcher.appendReplacement(buffer, "$1$3");
      }
      matcher.appendTail(buffer);
      content = buffer.toString();
      
      mav.addObject("dynamicForm", 
        this.workflowFlowtypeManager.getDynamicForm(workflowFile, content));
      WorkFlowUtil.removeEmptyFile(this.workflowFileManager.getWorkflowFile(id));
      mav.addObject("workflowFile", 
        this.workflowFileManager.getWorkflowFile(id));
      
      mav.addObject("canPrint", 
        Integer.valueOf(this.workflowFlowtypeManager.existWorkflowTemplate(workflowFile, "print")));
      
      UserSession user = (UserSession)request.getSession().getAttribute(
        org.springside.core.Constants.USER_IN_SESSION);
      String printer = "," + 
        workflowFile.getWorkflow().getSuperprinters() + ",";
      String userid = "," + user.getId() + ",";
      if ((workflowFile.getWorkflow().getSuperprinters() != null) && 
        (printer.indexOf(userid) > -1)) {
        mav.addObject("islookprintinfo", "true");
      }
      mav.addObject("currentFileinboxes", this.workflowFileinboxManager.findCurrentFileinbox(workflowFile.getId()));
      if ((workflowFile.getFromId() != null) && 
        (workflowFile.getFromId().intValue() != 0))
      {
        if (workflowFile.getFromType().intValue() < 3) {
          try
          {
            mav.addObject("relationFile", 
              this.workflowFileManager.getWorkflowFile(workflowFile.getFromId()));
          }
          catch (Exception e)
          {
            mav.addObject("relationFile", null);
          }
        }
        mav.addObject("relationFileId", StrUtils.getEncString(workflowFile.getFromId().toString()));
      }
      mav.addObject("isSuccess", Integer.valueOf(1));
      
      mav.addObject("printtemplates", 
        this.workflowFlowtypeManager
        .findWordtemplateByType(workflowFile.getWorkflowFlowtype().getId(), Integer.valueOf(3)));
    }
    else
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label7", "此文件可能已经被其他人删除！"));
      mav.addObject("isSuccess", Integer.valueOf(0));
    }
  }
  
  protected void referenceData(HttpServletRequest request, Map model)
  {
    String dict = this.dictManager.findDictByLabel("workflow.catalogy").getOptions();
    model.put("workflow_catalogy_dict", dict);
  }
  
  protected void onSave(HttpServletRequest request, HttpServletResponse response, ModelAndView mav, boolean isNew)
    throws Exception
  {
    WorkflowFile workflowFile = null;
    if (isNew)
    {
      workflowFile = new WorkflowFile();
    }
    else
    {
      Integer id = new Integer(request.getParameter("id"));
      workflowFile = this.workflowFileManager.getWorkflowFile(id);
    }
    BindingResult result = bindObject(request, workflowFile);
    if (result.hasErrors())
    {
      onBindError(request, result, mav, this.editView + "?method=" + (
        isNew ? "create" : "edit"));
      return;
    }
    this.workflowFileManager.saveWorkflowFile(workflowFile);
    
    saveMessage(request, getMessage(request, "common_label1", "数据") + (
      isNew ? getMessage(request, "common_label2", "新增") : 
      getMessage(request, "common_label3", "保存")) + 
      getMessage(request, "common_label4", "成功") + "!");
  }
  
  public ModelAndView remove(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    String lastAction = request.getParameter("lastAction");
    

    UserSession userSession = getUserSession(request);
    Integer fileId = new Integer(request.getParameter("id"));
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(fileId);
    if ((workflowFile != null) && (!this.workflowManager.getIsSupervisor(workflowFile.getWorkflow().getId(), userSession))) {
      createPermException(request, "协同审批->文件监控->重定位", null);
    }
    if ((lastAction == null) || ("".equals(lastAction))) {
      lastAction = "supervisor";
    }
    String methodUrl = "/modules/workflow/workflowFile.do?method=";
    if ("reportlist".equals(lastAction))
    {
      lastAction = 
        lastAction + "&flowId=" + request.getParameter("flowId") + "&fromReportToDel=yes";
      methodUrl = "redirect:/modules/count/workflowFileReport.do?method=";
      












      Map map = WebUtils.getParametersStartingWith(request, "search_");
      if ((map == null) || (map.size() == 0)) {
        map = (Map)request.getSession().getAttribute("queryInfoMap");
      }
      request.getSession().setAttribute("queryInfoMap", map);
    }
    ModelAndView mav = new ModelAndView(methodUrl + lastAction + 
      "&ec_s_submitdate=desc");
    
    onRemoveAll(request, response, mav);
    return mav;
  }
  
  public ModelAndView print(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
    
    this.workflowFileinboxManager.convertWorkflowFile(workflowFile);
    









    String fileFormat = request.getParameter("fileFormat");
    if ((fileFormat == null) || ("".equals(fileFormat)) || 
      ("html".equalsIgnoreCase(fileFormat)) || 
      ("htm".equalsIgnoreCase(fileFormat)))
    {
      String originalPrintForm = null;
      String strPrinttemplateId = request.getParameter("printtemplateId");
      if ((strPrinttemplateId == null) || 
        (strPrinttemplateId.trim().equals("")))
      {
        originalPrintForm = 
          this.workflowFlowtypeManager.getWorkflowTemplate(workflowFile, "print");
      }
      else
      {
        Integer wordTemplateId = new Integer(strPrinttemplateId);
        WorkflowWordtemplate workflowWordtemplate = this.workflowFlowtypeManager
          .getWorkflowWordtemplate(wordTemplateId);
        String serverfile = workflowWordtemplate.getServerfile();
        if (StorageUtil.exists(serverfile)) {
          originalPrintForm = StorageUtil.readFile(serverfile);
        } else {
          saveMessage(request, 
          
            getMessage(request, "WorkflowFileinboxManagerController_label22", "模板文件不存在，请联系系统管理员！"));
        }
      }
      String printForm = this.workflowFlowtypeManager.getPrintForm(
        workflowFile, originalPrintForm);
      
      UserSession user = (UserSession)request.getSession().getAttribute(
        org.springside.core.Constants.USER_IN_SESSION);
      if (printForm != null)
      {
        printForm = printForm.replaceAll("｛打印人｝", user.getName());
        
        String printDateStr = DateUtil.getToday();
        printForm = printForm.replaceAll("｛打印日期｝", printDateStr);
        
        int death = 0;
        for (;;)
        {
          death++;
          if (death > 20) {
            break;
          }
          int fstart = printForm.indexOf("｛打印日期｜");
          if (fstart < 0) {
            break;
          }
          int fend = printForm.indexOf("｝", fstart);
          if (fend < 0) {
            break;
          }
          String fstr = printForm.substring(fstart, fend + 1);
          
          String formatStr = fstr.substring(
            fstr.lastIndexOf("｜") + 1, fstr
            .lastIndexOf("｝"));
          try
          {
            printDateStr = DateUtil.format(
              DateUtil.getDate(), formatStr);
          }
          catch (Exception e)
          {
            System.out.println(fstr + 
              "，打印日期格式设置不正确，使用默认格式打印输出！");
          }
          printForm = 
            printForm.replaceAll(fstr, printDateStr);
        }
      }
      if ("htm".equals(org.springside.core.Constants.WORKFLOW_PRINT_FORMAT))
      {
        response.setContentType("text/html; charset=UTF-8");
      }
      else
      {
        String url = "http://" + request.getServerName() + ":" + 
          request.getServerPort() + request.getContextPath() + 
          "/modules/setting/workflowSignature.do";
        printForm = printForm.replaceAll(
          "../../modules/setting/workflowSignature.do", url);
        














        response.setContentType("application/msword; charset=GBK");
      }
      String filename = workflowFile.getTitle().replaceAll("[\n\r]", " ") + 
        "." + org.springside.core.Constants.WORKFLOW_PRINT_FORMAT;
      
      response.setHeader("Content-Disposition", "attachment; filename=" + 
        new String(filename.getBytes("GBK"), "ISO-8859-1"));
      
      response.getWriter().write(printForm);
    }
    else if ("doc".equalsIgnoreCase(fileFormat))
    {
      printWord(request, response);
    }
    return null;
  }
  
  public ModelAndView goToPrint(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView(
      "/modules/workflow/workflowFile_wordprint.jsp");
    Integer id = new Integer(request.getParameter("workflowFileId"));
    WorkflowFile workflowFile = null;
    try
    {
      workflowFile = this.workflowFileManager.getWorkflowFile(id);
    }
    catch (Exception e)
    {
      this.logger.error(e);
    }
    if (workflowFile == null)
    {
      mav.addObject("isDeleted", "yes");
      return mav;
    }
    mav.addObject("workflowFile", workflowFile);
    if (workflowFile.getPriority() != null)
    {
      String myValue = 
        (String)org.springside.core.Constants.WORKFLOW_PRIORITY_MAP.get(workflowFile.getPriority());
      if (myValue == null) {
        myValue = "";
      }
      if (myValue.startsWith("!")) {
        myValue = myValue.substring(1);
      }
      mav.addObject("priority", myValue);
    }
    else
    {
      mav.addObject("priority", "");
    }
    List<WorkflowFlowfield> list = this.workflowFlowfieldManager
      .findAllWorkflowFlowfieldByFlwotypeId(workflowFile
      .getWorkflow().getFlowtypeId());
    
    Map<Integer, Integer> shortListMap = new HashMap();
    Map<Integer, Integer> longListMap = new HashMap();
    
    this.workflowFlowtypeManager.getFieldListMap(workflowFile, shortListMap, longListMap);
    for (WorkflowFlowfield workflowFlowfield : list) {
      if (workflowFlowfield.getFieldtype().equals("list")) {
        workflowFlowfield.setFieldserial(Integer.valueOf(this.workflowFlowtypeManager.getIndex(workflowFlowfield, shortListMap, longListMap)));
      }
    }
    mav.addObject("workflowFlowfields", list);
    mav.addObject("workflowsignrecord", org.springside.core.Constants.WORKFLOW_SIGN_RECORD);
    return mav;
  }
  
  public ModelAndView printWord(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
    
    String strPrinttemplateId = request.getParameter("printtemplateId");
    if ((strPrinttemplateId == null) || (strPrinttemplateId.trim().equals("")))
    {
      defaultPrint(request, response, workflowFile);
    }
    else
    {
      Integer wordTemplateId = new Integer(strPrinttemplateId);
      WorkflowWordtemplate workflowWordtemplate = this.workflowFlowtypeManager
        .getWorkflowWordtemplate(wordTemplateId);
      String serverfile = workflowWordtemplate.getServerfile();
      if (StorageUtil.exists(serverfile))
      {
        response.setContentType(workflowWordtemplate.getFileext());
        
        response.setContentLength(new Integer(
          String.valueOf(StorageUtil.getSize(serverfile))).intValue());
        
        response.setHeader("Content-Disposition", 
          "attachment; filename=" + 
          new String(
          workflowWordtemplate.getFilename().getBytes("GBK"), "ISO-8859-1"));
        StorageUtil.download(serverfile, response.getOutputStream());
      }
      else
      {
        saveMessage(request, 
        
          getMessage(request, "WorkflowFileinboxManagerController_label22", "模板文件不存在，请联系系统管理员！"));
      }
    }
    return null;
  }
  
  private void defaultPrint(HttpServletRequest request, HttpServletResponse response, WorkflowFile workflowFile)
    throws BusinessException, UnsupportedEncodingException, IOException
  {
    String originalPrintForm = this.workflowFlowtypeManager.getWorkflowTemplate(
      workflowFile, "print");
    String printForm = this.workflowFlowtypeManager.getPrintForm(workflowFile, 
      originalPrintForm);
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    if (printForm != null)
    {
      printForm = printForm.replaceAll("｛打印人｝", user.getName());
      
      String printDateStr = DateUtil.getToday();
      printForm = printForm.replaceAll("｛打印日期｝", printDateStr);
      int death = 0;
      for (;;)
      {
        death++;
        if (death > 20) {
          break;
        }
        int fstart = printForm.indexOf("｛打印日期｜");
        if (fstart < 0) {
          break;
        }
        int fend = printForm.indexOf("｝", fstart);
        if (fend < 0) {
          break;
        }
        String fstr = printForm.substring(fstart, fend + 1);
        
        String formatStr = fstr.substring(
          fstr.lastIndexOf("｜") + 1, 
          fstr.lastIndexOf("｝"));
        try
        {
          printDateStr = DateUtil.format(DateUtil.getDate(), 
            formatStr);
        }
        catch (Exception e)
        {
          System.out.println(fstr + 
            "，打印日期格式设置不正确，使用默认格式打印输出！");
        }
        printForm = printForm.replaceAll(fstr, printDateStr);
      }
    }
    if ("htm".equals(org.springside.core.Constants.WORKFLOW_PRINT_FORMAT))
    {
      response.setContentType("text/html; charset=UTF-8");
    }
    else
    {
      String url = "http://" + request.getServerName() + ":" + 
        request.getServerPort() + request.getContextPath() + 
        "/modules/setting/workflowSignature.do";
      printForm = printForm.replaceAll(
        "../../modules/setting/workflowSignature.do", url);
      
      response.setContentType("application/msword; charset=GBK");
    }
    String filename = workflowFile.getTitle().replaceAll("[\n\r]", " ") + 
      "." + org.springside.core.Constants.WORKFLOW_PRINT_FORMAT;
    response.setHeader("Content-Disposition", "attachment; filename=" + 
      new String(filename.getBytes("GBK"), "ISO-8859-1"));
    response.getWriter().write(printForm);
  }
  
  public ModelAndView findRePositionInfo(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView(
      "/modules/workflow/workflowfile_repositioninfo.jsp");
    String id = request.getParameter("workflowFileId");
    Map filterMap = new HashMap();
    Map sortMap = new LinkedHashMap();
    filterMap.put("inboxstatus_i_eq", Integer.valueOf(7));
    filterMap.put("workflowFileXXid_i_eq", id);
    
    sortMap.put("rePositionDate", "asc");
    List<WorkflowFileprocess> list = this.workflowFileManager.findProcess(
      filterMap, sortMap);
    mav.addObject("workflowFileRepositionInfoList", list);
    return mav;
  }
  
  protected void onRemoveAll(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    













    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    if (!this.workflowFileManager.getExistById(id))
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label7", "此文件可能已经被其他人删除！"));
      return;
    }
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(id);
    if ((workflowFile.getWorkflow().getSupervisors() != null) && 
      (workflowFile.getWorkflow().getSupervisors().indexOf(
      " " + user.getId() + " ") >= 0))
    {
      this.workflowFileManager.removeWorkflowFile(id);
      






























      StringBuffer ids = new StringBuffer();
      Set<WorkflowFileinbox> workflowFileinboxs = workflowFile
        .getWorkflowFileinboxes();
      for (WorkflowFileinbox workflowFileinbox : workflowFileinboxs) {
        ids.append(workflowFileinbox.getId() + ",");
      }
      if (ids.length() > 0) {
        ids.setLength(ids.length() - 1);
      }
      Map filter1 = new HashMap();
      filter1.put("entityId_i_in", ids);
      List messagesList = this.messagesManager.findMessages(filter1);
      for (int j = 0; j < messagesList.size(); j++)
      {
        Messages messages = (Messages)messagesList.get(j);
        this.messagesManager.removeMessages(messages.getId());
      }
      this.workflowFilelockManager.removeWorkflowFilelock(id);
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label8", "成功删除公文"));
    }
    else
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label10", "您无权删除此公文"));
    }
  }
  
  public ModelAndView draft(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_draft.jsp");
    
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    

    String fromId = request.getParameter("fromId");
    String inboxId = request.getParameter("inboxId");
    











    Map map = WebUtils.getParametersStartingWith(request, "search_");
    

    map.put("catalogy_s_ne", "费用报销");
    

    mav.addObject("workflows", this.workflowManager.findWorkflow(map, user));
    




    mav.addObject("workflowFlowfavorMap", 
      this.workflowManager.findWorkflowFlowfavorMap(user));
    
    mav.addAllObjects(referenceData(request));
    
    String ec_token = request.getParameter("ec_token");
    mav.addObject("ec_token", ec_token);
    String ec_cu = request.getParameter("ec_cu");
    mav.addObject("ec_cu", ec_cu);
    



    String dict = this.dictManager.findDictByLabel("workflow.catalogy").getOptions();
    

    dict = ("/" + dict + "/").replaceAll("/费用报销/", "/");
    dict = dict.substring(1, dict.length() - 1);
    Map model = new HashMap();
    model.put("workflow_catalogy_dict", dict);
    
    mav.addAllObjects(model);
    
    return mav;
  }
  
  public boolean getCanDraft(String fileId, String inboxId, UserSession user)
  {
    boolean flag = false;
    if (StringUtils.isBlank(fileId)) {
      return flag;
    }
    if (Integer.valueOf(fileId).intValue() != 0)
    {
      if (StringUtils.isBlank(inboxId))
      {
        WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(Integer.valueOf(fileId));
        if ((workflowFile != null) && (workflowFile.getFlowFlag().intValue() != 0))
        {
          flag = this.workflowManager.getIsObservers(workflowFile.getWorkflow().getId(), user);
          if (!flag) {
            flag = this.workflowManager.getIsSupervisor(workflowFile.getWorkflow().getId(), user);
          }
          if (!flag) {
            flag = this.workflowFlowRightManager.getWorkflowPerm(workflowFile.getWorkflow().getId(), user.getId());
          }
        }
      }
      else if (this.workflowFileinboxManager.getHavePermOfInboxAllStatus(user, inboxId))
      {
        WorkflowFileinbox workflowFileinbox = this.workflowFileinboxManager.getWorkflowFileinbox(Integer.valueOf(inboxId));
        if ((1 != workflowFileinbox.getIssent().intValue()) && (workflowFileinbox.getIsspecial().intValue() == 0)) {
          flag = true;
        }
      }
      Integer ParentflowId = this.workflowFileManager.getWorkflowFile(Integer.valueOf(fileId)).getWorkflow().getParentId();
      if (this.workflowFileManager.isArchiveMan(ParentflowId, user)) {
        flag = true;
      }
    }
    else if (StringUtils.isBlank(inboxId))
    {
      flag = true;
    }
    return flag;
  }
  
  public ModelAndView report(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_report.jsp");
    
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    

    mav.addObject("workflows", this.workflowManager.findWorkflow(map, user));
    

















    mav.addAllObjects(referenceData(request));
    



    return mav;
  }
  
  public ModelAndView agent(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_agent.jsp");
    return agent(request, response, mav);
  }
  
  public ModelAndView agent(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {
    mav.setViewName("/modules/workflow/workflow_agent.jsp");
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    map.put("status_i_eq", "1");
    

    List<Workflow> workflows = this.workflowManager.findWorkflow(map);
    










    Map agentMap = this.workflowManager.findWorkflowFlowagentMap(user);
    
    List workflowes = new ArrayList();
    String agentFlowIds = "";
    for (Workflow flow : workflows) {
      if (agentMap.get(flow.getParentId()) != null)
      {
        workflowes.add(flow);
        agentFlowIds = agentFlowIds + flow.getId() + ",";
      }
    }
    mav.addObject("workflows", workflowes);
    mav.addObject("workflowFlowagentMap", agentMap);
    mav.addObject("agentFlowIds", agentFlowIds);
    mav.addAllObjects(referenceData(request));
    
    return mav;
  }
  
  public ModelAndView agent2me(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_agent2me.jsp");
    
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    


















    List<WorkflowFlowagent> agentList = this.workflowManager
      .findWorkflowFlowagent2me(map, user);
    String flowagentIds = "";
    for (int i = 0; i < agentList.size(); i++)
    {
      WorkflowFlowagent flowagent = (WorkflowFlowagent)agentList.get(i);
      if (flowagentIds.equals("")) {
        flowagentIds = flowagentIds + flowagent.getFlowPid();
      } else {
        flowagentIds = flowagentIds + "," + flowagent.getFlowPid();
      }
    }
    Map filter = new HashMap();
    filter.put("parentId_i_in", flowagentIds);
    mav.addObject("workflowList", this.workflowManager.findWorkflow(filter));
    mav.addObject("workflowFlowagents", 
      this.workflowManager.findWorkflowFlowagent2me(map, user));
    
    mav.addAllObjects(referenceData(request));
    
    return mav;
  }
  
  public ModelAndView agentother(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_agent_other.jsp");
    
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    
    Map map2 = new HashMap();
    List<Workflow> workflowList = this.workflowManager.findWorkflow(map2, user);
    String workflowIds = "";
    for (int i = 0; i < workflowList.size(); i++)
    {
      Workflow workflow = (Workflow)workflowList.get(i);
      if (workflowIds.equals("")) {
        workflowIds = workflow.getId().toString();
      } else {
        workflowIds = workflowIds + "," + workflow.getId();
      }
    }
    map.put("id_i_not", workflowIds);
    map.put("status_i_eq", "1");
    
    mav.addObject("workflows", this.workflowManager.findWorkflow(map));
    













    mav.addObject("workflowFlowagentMap", 
      this.workflowManager.findWorkflowFlowagentMap(user));
    mav.addAllObjects(referenceData(request));
    return mav;
  }
  
  public ModelAndView saveFavor(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer flowId = new Integer(request.getParameter("id"));
    Integer parentFlowId = Integer.valueOf(Integer.parseInt(request.getParameter("parentFlowId")));
    

    UserSession userSession = getUserSession(request);
    if (!this.workflowManager.getCanOperate(flowId, userSession)) {
      createPermException(request, "协同审批->新建公文->收藏", null);
    }
    this.workflowManager.saveFavor(userSession.getId(), parentFlowId);
    
    return draft(request, response);
  }
  
  public ModelAndView saveAgentAll(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_agent.jsp");
    






    String refreshFrame = request.getParameter("refreshFrame");
    if (refreshFrame != null) {
      return agent(request, response, mav);
    }
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Integer userId = new Integer(request.getParameter("allUserId"));
    String startdate = request.getParameter("allStartdate");
    String enddate = request.getParameter("allenddate");
    String workflowIds = ServletRequestUtils.getStringParameter(request, "workflowIds", "");
    String workflowNames = ServletRequestUtils.getStringParameter(request, "workflowNames", "");
    String isallfile = request.getParameter("isallfile");
    if ((isallfile == null) || (!"1".equals(isallfile))) {
      isallfile = "0";
    }
    int succ = 0;
    int fail = 0;
    
    Map map = new HashMap();
    map.put("id_i_in", workflowIds);
    

    List<String> nameStrList = new ArrayList();
    
    StringBuilder nameBuffer = new StringBuilder();
    StringBuilder tempSb = null;
    if (!user.getId().equals(userId))
    {
      List workflowList = this.workflowManager.findWorkflow(map);
      String flowName = null;
      String flowId = null;
      for (int i = 0; i < workflowList.size(); i++)
      {
        Workflow workflow = (Workflow)workflowList.get(i);
        
        tempSb = new StringBuilder(nameBuffer.toString());
        tempSb.append(workflow.getName()).append(",");
        if (tempSb.length() < 450)
        {
          nameBuffer.append(workflow.getName());
          nameBuffer.append(",");
        }
        else
        {
          nameStrList.add(nameBuffer.toString());
          nameBuffer = new StringBuilder();
          nameBuffer.append(workflow.getName());
          nameBuffer.append(",");
        }
        if (this.workflowManager.saveAgent(user.getId(), 
          workflow.getParentId(), userId, startdate, enddate, Integer.valueOf(isallfile)))
        {
          succ++;
        }
        else
        {
          fail++;
          if (flowName == null)
          {
            flowName = workflow.getName();
            flowId = workflow.getId().toString();
          }
          else
          {
            flowName = flowName + "、" + workflow.getName();
            flowId = flowId + "," + workflow.getId();
          }
        }
      }
      nameStrList.add(nameBuffer.toString());
      

      String message = "";
      if (succ > 0)
      {
        message = 
        

          getMessage(request, "WorkflowFileManagerController_label11", "成功委托了") + succ + getMessage(request, "WorkflowFileManagerController_label49", "个流程");
        saveMessage(request, message);
      }
      if (fail > 0)
      {
        message = flowName + " " + fail + getMessage(request, "WorkflowFileManagerController_label66", "个流程委托失败，对方已经将此流程委托给你，流程不能相互委托！");
        saveMessage(request, message);
        mav.addObject("failFlowName", flowName.replaceAll("、", ","));
        mav.addObject("failFlowId", flowId);
        mav.addObject("startdate", startdate);
        mav.addObject("enddate", enddate);
        mav.addObject("isallfile", isallfile);
      }
      for (String str : nameStrList)
      {
        String title = getMessage(request, "WorkflowFileManagerController_label37", "委托流程[") + 
          str.split(",", 0).length + getMessage(request, "WorkflowFileManagerController_label49", "个流程") + 
          getMessage(request, "WorkflowFileManagerController_label38", "],请查阅,来自[公文处理]");
        
        String content = user.getName() + getMessage(request, "WorkflowFileManagerController_label35", "已将【") + 
          str.substring(0, str.toString().length() - 1) + "】" + 
          getMessage(request, "WorkflowFileManagerController_label21", "流程委托给你办理！");
        
        this.workflowFileinboxManager.saveAgentMessages(userId, user, title, content);
      }
    }
    else
    {
      mav.addObject("failFlowName", workflowNames);
      mav.addObject("failFlowId", workflowIds);
      mav.addObject("startdate", startdate);
      mav.addObject("enddate", enddate);
      mav.addObject("isallfile", isallfile);
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label16", "不能委托给自己!"));
    }
    return agent(request, response, mav);
  }
  
  public ModelAndView removeAgentOtherAll(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    List<Workflow> workflow = this.workflowManager.findWorkflow(new HashMap(), 
      user);
    String workflowIds = "";
    for (Workflow workflow2 : workflow) {
      if (workflowIds.equals("")) {
        workflowIds = workflow2.getParentId().toString();
      } else {
        workflowIds = workflowIds + "," + workflow2.getParentId();
      }
    }
    Map map = new HashMap();
    map.put("flowPid_i_not", workflowIds);
    map.put("status_i_eq", "1");
    map.put("userByFromuserIdXXid_i_eq", user.getId().toString());
    Object agentList = this.workflowManager
      .findWorkflowFlowagent(map);
    

    String backStr = getMessage(request, 
      "WorkflowFileManagerController_labe160", "已成功取回");
    












    String fileStr = getMessage(request, 
      "WorkflowFileManagerController_labe161", "份文件。");
    
    String consignerStr = getMessage(request, 
      "WorkflowFileManagerController_labe162", "份文件受托人");
    













    String signedinStr = getMessage(request, 
      "WorkflowFileManagerController_labe163", "已签收");
    
    String notBackStr = getMessage(request, 
      "WorkflowFileManagerController_labe164", "不能被取回！");
    
    int totalBackNum = 0;
    
    StringBuffer notBackSb = new StringBuffer();
    for (int i = 0; i < ((List)agentList).size(); i++)
    {
      WorkflowFlowagent workflowFlowagent = 
        (WorkflowFlowagent)((List)agentList).get(i);
      String returnValue = this.workflowManager.removeAgent(
        workflowFlowagent.getId());
      if (returnValue.length() > 0)
      {
        String takeBackNum = returnValue.split(",")[0];
        













        String notTakeBackNum = returnValue.split(",")[1];
        
        String assignee = returnValue.split(",")[2];
        totalBackNum += Integer.valueOf(takeBackNum).intValue();
        if (!"0".equals(notTakeBackNum)) {
          notBackSb.append(notTakeBackNum).append(consignerStr).append(assignee).append(signedinStr).append(",");
        }
      }
    }
    if (notBackSb.length() > 0)
    {
      notBackSb.append(notBackStr);
      saveMessage(request, backStr + totalBackNum + fileStr + 
        notBackSb.toString());
    }
    else
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label23", "成功取消") + 
        ((List)agentList).size() + 
        getMessage(request, 
        "WorkflowFileManagerController_label24", "个委托流程！"));
    }
    return agentother(request, response);
  }
  
  public ModelAndView removeAgentAll(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    List<Workflow> workflow = this.workflowManager.findWorkflow(new HashMap(), 
      user);
    
    String workflowIds = "";
    for (Workflow workflow2 : workflow) {
      if (workflowIds.equals("")) {
        workflowIds = workflow2.getParentId().toString();
      } else {
        workflowIds = workflowIds + "," + workflow2.getParentId();
      }
    }
    Map map = new HashMap();
    map.put("flowPid_i_in", workflowIds);
    
    map.put("status_i_eq", "1");
    map.put("userByFromuserIdXXid_i_eq", user.getId().toString());
    Object agentList = this.workflowManager
      .findWorkflowFlowagent(map);
    

    String backStr = getMessage(request, 
      "WorkflowFileManagerController_labe160", "已成功取回");
    












    String fileStr = getMessage(request, 
      "WorkflowFileManagerController_labe161", "份文件。");
    
    String consignerStr = getMessage(request, 
      "WorkflowFileManagerController_labe162", "份文件受托人");
    













    String signedinStr = getMessage(request, 
      "WorkflowFileManagerController_labe163", "已签收");
    
    String notBackStr = getMessage(request, 
      "WorkflowFileManagerController_labe164", "不能被取回！");
    
    int totalBackNum = 0;
    
    StringBuffer notBackSb = new StringBuffer();
    for (int i = 0; i < ((List)agentList).size(); i++)
    {
      WorkflowFlowagent workflowFlowagent = 
        (WorkflowFlowagent)((List)agentList).get(i);
      
      String returnValue = this.workflowManager.removeAgent(
        workflowFlowagent.getId());
      if (returnValue.length() > 0)
      {
        String takeBackNum = returnValue.split(",")[0];
        













        String notTakeBackNum = returnValue.split(",")[1];
        
        String assignee = returnValue.split(",")[2];
        totalBackNum += Integer.valueOf(takeBackNum).intValue();
        if (!"0".equals(notTakeBackNum)) {
          notBackSb.append(notTakeBackNum).append(consignerStr).append(assignee).append(signedinStr).append(",");
        }
      }
    }
    if (notBackSb.length() > 0)
    {
      notBackSb.append(notBackStr);
      saveMessage(request, backStr + totalBackNum + fileStr + 
        notBackSb.toString());
    }
    else
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label23", "成功取消委托的") + 
        ((List)agentList).size() + 
        getMessage(request, 
        "WorkflowFileManagerController_label24", "流程！"));
    }
    return agent(request, response);
  }
  
  public ModelAndView removeAgentOther(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    











    UserSession userSession = getUserSession(request);
    WorkflowFlowagent workflowFlowagent = this.workflowManager.getWorkflowFlowagent(id);
    if ((workflowFlowagent == null) || 
      (userSession.getId().intValue() != workflowFlowagent.getUserByFromuserId().getId().intValue())) {
      createPermException(request, "事务委托->取消委托", null);
    }
    String returnValue = this.workflowManager.removeAgent(id);
    if (returnValue.length() == 0)
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label25", "取消委托成功！"));
    }
    else
    {
      String takeBackNum = returnValue.split(",")[0];
      













      String notTakeBackNum = returnValue.split(",")[1];
      
      String assignee = returnValue.split(",")[2];
      
      String backStr = getMessage(request, 
        "WorkflowFileManagerController_labe160", "已成功取回");
      












      String fileStr = getMessage(request, 
        "WorkflowFileManagerController_labe161", "份文件。");
      
      String consignerStr = getMessage(request, 
        "WorkflowFileManagerController_labe162", "份文件受托人");
      













      String signedinStr = getMessage(request, 
        "WorkflowFileManagerController_labe163", "已签收");
      
      String notBackStr = getMessage(request, 
        "WorkflowFileManagerController_labe164", "不能被取回！");
      if (!"0".equals(notTakeBackNum)) {
        saveMessage(request, backStr + takeBackNum + fileStr + 
          notTakeBackNum + consignerStr + assignee + 
          signedinStr + "," + notBackStr);
      } else {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label25", "取消委托成功！"));
      }
    }
    return agentother(request, response);
  }
  
  public ModelAndView removeAgent(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer id = new Integer(request.getParameter("id"));
    










    UserSession userSession = getUserSession(request);
    WorkflowFlowagent workflowFlowagent = this.workflowManager.getWorkflowFlowagent(id);
    if ((workflowFlowagent == null) || 
      (userSession.getId().intValue() != workflowFlowagent.getUserByFromuserId().getId().intValue())) {
      createPermException(request, "事务委托->取消委托", null);
    }
    String returnValue = this.workflowManager.removeAgent(id);
    if (returnValue.length() == 0)
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label25", "撤消委托成功！"));
    }
    else
    {
      String takeBackNum = returnValue.split(",")[0];
      













      String notTakeBackNum = returnValue.split(",")[1];
      
      String assignee = returnValue.split(",")[2];
      
      String backStr = getMessage(request, 
        "WorkflowFileManagerController_labe160", "已成功取回");
      












      String fileStr = getMessage(request, 
        "WorkflowFileManagerController_labe161", "份文件。");
      
      String consignerStr = getMessage(request, 
        "WorkflowFileManagerController_labe162", "份文件受托人");
      













      String signedinStr = getMessage(request, 
        "WorkflowFileManagerController_labe163", "已签收");
      
      String notBackStr = getMessage(request, 
        "WorkflowFileManagerController_labe164", "不能被取回！");
      if (!"0".equals(notTakeBackNum)) {
        saveMessage(request, backStr + takeBackNum + fileStr + 
          notTakeBackNum + consignerStr + assignee + 
          signedinStr + "," + notBackStr);
      } else {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label25", "撤消委托成功！"));
      }
    }
    return agent(request, response);
  }
  
  public ModelAndView removeAgentSelect(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    String[] ids = request.getParameterValues("itemlist");
    if (ids != null)
    {
      UserSession userSession = getUserSession(request);
      WorkflowFlowagent workflowFlowagent = null;
      for (String id : ids)
      {
        workflowFlowagent = this.workflowManager.getWorkflowFlowagent(Integer.valueOf(id));
        if ((workflowFlowagent == null) || 
          (userSession.getId().intValue() != workflowFlowagent.getUserByFromuserId().getId().intValue())) {
          createPermException(request, "事务委托->取消委托", null);
        }
      }
      for (int i = 0; i < ids.length; i++) {
        this.workflowManager.removeAgent(new Integer(ids[i]));
      }
    }
    saveMessage(request, 
      getMessage(request, "WorkflowFileManagerController_label25", "撤消委托成功！"));
    return agent(request, response);
  }
  
  public ModelAndView removeFavor(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    
    Integer flowId = new Integer(request.getParameter("parentFlowId"));
    this.workflowManager.removeFavor(user.getId(), flowId);
    
    return draft(request, response);
  }
  
  public ModelAndView showFlow(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_show.jsp");
    Integer id = new Integer(request.getParameter("id"));
    





    onWorkflowShow(request, response, mav, id);
    
    return mav;
  }
  
  protected void onWorkflowShow(HttpServletRequest request, HttpServletResponse response, ModelAndView mav, Integer id)
    throws Exception
  {
    Workflow workflow = this.workflowManager.getWorkflow(id);
    mav.addObject("workflow", workflow);
    
    mav
      .addObject("workflowvers", 
      this.workflowManager
      .findWorkflowVer(this.workflowManager.getWorkflow(id).getParentId()));
    













    Map<String, String> stepOrderMap = new LinkedHashMap();
    stepOrderMap.put("posy", "asc");
    stepOrderMap.put("posx", "asc");
    List<WorkflowStep> steps = this.workflowStepManager.findWorkflowStepByFlowId(id);
    Collections.sort(steps, ObjectComparator.instance(stepOrderMap));
    mav.addObject("workflowSteps", steps);
    


















    Map<Integer, List<WorkflowStep>> stepMap = new HashMap();
    for (WorkflowStep step : steps) {
      try
      {
        List<WorkflowStep> afterSteps = new ArrayList();
        afterSteps.add(this.workflowStepManager.getWorkflowStep(Integer.valueOf(Integer.parseInt(step.getTrueWfnid()))));
        if (step.getHasfalse().intValue() == 1)
        {
          String[] ids = step.getFalseWfnid().split("x");
          for (String sid : ids) {
            afterSteps.add(this.workflowStepManager.getWorkflowStep(Integer.valueOf(Integer.parseInt(sid))));
          }
        }
        Collections.sort(afterSteps, ObjectComparator.instance(stepOrderMap));
        stepMap.put(step.getId(), afterSteps);
      }
      catch (Exception e)
      {
        this.logger.error(e);
      }
    }
    mav.addObject("stepMap", stepMap);
    




























    mav.addObject("TRANSACTIONID", "0");
    













    mav.addObject("workflowSteptypeMap", 
      this.workflowStepManager.findWorkflowSteptype());
    


    mav.addObject("workflowFlowtype", 
      this.workflowFlowtypeManager.getWorkflowFlowtype(workflow.getFlowtypeId()));
    
    mav.addObject("deptNames", this.workflowManager
      .getDeptNames(workflow.getDepts()));
    mav.addObject("userNames", this.workflowManager
      .getUserNames(workflow.getUsers()));
    mav.addObject("observerNames", this.workflowManager
      .getUserNames(workflow.getObservers()));
    mav.addObject("supervisorNames", this.workflowManager
      .getUserNames(workflow.getSupervisors()));
    












    mav.addObject("superobserversNames", this.workflowManager
      .getUserNames(workflow.getSuperobservers()));
    
    mav.addObject("fileDirectionEnum", 
      cn.firstsoft.modules.workflow.Constants.fileDirectionEnum());
  }
  
  public ModelAndView toArchive(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView(
      "/modules/workflow/workflow_toarchive_list.jsp");
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    





    String fromType = ServletRequestUtils.getStringParameter(request, "fromType", "knowledge");
    if (!ContextUtils.isValidModule("knowledge").booleanValue()) {
      fromType = "archive";
    }
    String managerProperties = "/workflow/config" + 
      File.separator + "manager.properties";
    File f = StorageUtil.getFile(managerProperties);
    StringBuilder knowledge_pids = new StringBuilder("-1");
    



    StringBuilder archive_pids = new StringBuilder("-1");
    if (f.exists())
    {
      Properties p = new Properties();
      p.load(new FileInputStream(f));
      if (p.containsValue(user.getId().toString()))
      {
        Set<Object> set = p.keySet();
        for (Object o : set)
        {
          String key = o.toString();
          String value = p.getProperty(key, "0");
          if (value.equals(user.getId().toString()))
          {
            String xmlFile = org.springside.core.Constants.MAIN_STORAGE_DIR + File.separator + "/workflow/config" + 
              File.separator + "archive_" + key + ".xml";
            File file = new File(xmlFile);
            if (file.exists())
            {
              SAXBuilder builder = new SAXBuilder();
              Document doc = builder.build(new File(xmlFile));
              Element archive_config = doc.getRootElement().getChild("archive");
              String archiveTrans = archive_config.getChild("trans").getText();
              if ("1".equals(archiveTrans)) {
                archive_pids.append("," + key);
              }
              Element knowledge = doc.getRootElement().getChild("knowledge");
              String knowledgeTrans = knowledge.getChild("trans").getText();
              if ("1".equals(knowledgeTrans)) {
                knowledge_pids.append("," + key);
              }
            }
          }
        }
      }
    }
    Map<String, String> map = WebUtils.getParametersStartingWith(request, 
      "search_");
    if ("knowledge".equals(fromType))
    {
      map.put("archive_i_not", "1,5");
      map.put("workflowXXparentId_i_in", knowledge_pids.toString());
    }
    else
    {
      map.put("archive_i_not", "2,5");
      map.put("workflowXXparentId_i_in", archive_pids.toString());
    }
    map.put("archive_i_lt", "3");
    map.put("flowFlag_i_eq", "1");
    if ((this.toArchiveAdapter instanceof ToArchiveNew))
    {
      if (this.workflowManager.hasArchiveModules()) {
        mav.addObject("showArchive", "yes");
      } else {
        map.put("archive_i_ne", "1");
      }
    }
    else if ((this.toArchiveAdapter instanceof ToArchive)) {
      mav.addObject("showArchive", "yes");
    }
    if (StringUtils.isNotBlank(request.getParameter("deptIds")))
    {
      map.remove("deptXXname_s_like");
      map.put("deptXXid_i_eq", request.getParameter("deptIds"));
    }
    PageSortModel psm = new PageSortModel(request, "ec");
    
    List<WorkflowFile> workflowFiles = this.workflowFileManager
      .findWorkflowFileByPage(map, psm);
    
    mav.addObject("workflowFiles", workflowFiles);
    mav.addObject("priorityMap", org.springside.core.Constants.WORKFLOW_PRIORITY_MAP);
    mav.addObject("fromType", fromType);
    



    return mav;
  }
  
  public ModelAndView toArchiveProcess(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView(
      "/modules/workflow/workflow_toarchive_list.jsp");
    
    String fromType = ServletRequestUtils.getStringParameter(request, "fromType", "knowledge");
    mav.addObject("fromType", fromType);
    int[] itemlist = ServletRequestUtils.getIntParameters(request, "itemlist");
    if ((itemlist != null) && (itemlist.length > 0))
    {
      List<Workflow> flows = new ArrayList();
      
      UserSession userSession = getUserSession(request);
      WorkflowFile wf = null;
      String havePermFlowIds = this.workflowManager.getArchiveManager(String.valueOf(userSession.getId()));
      int[] arrayOfInt1;
      int j = (arrayOfInt1 = itemlist).length;
      for (int i = 0; i < j; i++)
      {
        Integer fileId = Integer.valueOf(arrayOfInt1[i]);
        wf = this.workflowFileManager.getWorkflowFile(fileId);
        if ((wf == null) || 
          (!StrUtils.getIsExistIDs(havePermFlowIds, String.valueOf(wf.getWorkflow().getParentId())))) {
          createPermException(request, "流程归档->归档", null);
        } else if (!this.workflowFileManager.getCanToArchive(fromType, wf)) {
          createPermException(request, "流程归档->归档", "流程未结束！或者已归档");
        }
        if (!flows.contains(wf.getWorkflow())) {
          flows.add(wf.getWorkflow());
        }
      }
      StringBuilder sb = new StringBuilder("-1");
      for (int i : itemlist) {
        sb.append("," + i);
      }
      Object map = new HashMap();
      ((Map)map).put("id_i_in", sb.toString());
      PageSortModel psm = new PageSortModel(request, "ec");
      
      psm.setPageNo(1);
      Object workflowFiles = this.workflowFileManager
        .findWorkflowFileByPage((Map)map, psm);
      mav.addObject("workflowFiles", workflowFiles);
      mav.addObject("priorityMap", org.springside.core.Constants.WORKFLOW_PRIORITY_MAP);
      if ((flows != null) && (flows.size() == 1) && ("knowledge".equals(fromType)))
      {
        mav.addObject("showFields", Boolean.valueOf(true));
        Workflow flow = (Workflow)flows.get(0);
        Map<String, String> fmap = new HashMap();
        fmap.put("flowtypeId_i_eq", String.valueOf(flow.getFlowtypeId()));
        fmap.put("fieldtype_s_ne", "list");
        List<WorkflowFlowfield> flowfields = this.workflowFlowfieldManager.findWorkflowFlowfield(fmap);
        List<WorkflowFlowfield> workflowFlowfields = new ArrayList();
        workflowFlowfields.addAll(flowfields);
        
        this.workflowFileManager.hasWorkFlowFields(workflowFlowfields);
        List<Map> knowledgeColumns = this.workflowFileManager.getKnowledgeFields(null);
        if (workflowFlowfields.size() > 0)
        {
          mav.addObject("knowledgeColumns", knowledgeColumns);
          mav.addObject("knowledgeFlowfields", workflowFlowfields);
        }
      }
    }
    else
    {
      saveMessage(request, 
        getMessage(request, "WorkflowFileManagerController_label26", "请选择需归档的流程文件数据！"));
      mav
        .setViewName("redirect:/modules/workflow/workflowFile.do?method=toArchive");
    }
    return mav;
  }
  
  public ModelAndView toArchiveFinish(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    String fromType = ServletRequestUtils.getStringParameter(request, "fromType", "knowledge");
    ModelAndView mav;
    if ("knowledge".equals(fromType)) {
      mav = new ModelAndView(
        "redirect:/modules/workflow/workflowFile.do?method=toArchive");
    } else {
      mav = new ModelAndView(
        "/modules/workflow/workflowFile.do?method=toArchive");
    }
    UserSession userSession = getUserSession(request);
    int[] itemlist = ServletRequestUtils.getIntParameters(request, "itemlist");
    int type = ServletRequestUtils.getIntParameter(request, "type", 1);
    mav.addObject("fromType", fromType);
    Object workflowFiles;
    WorkflowArchive workflowArchive;
    if ((itemlist != null) && (itemlist.length > 0))
    {
      WorkflowFile wf = null;
      String havePermFlowIds = this.workflowManager.getArchiveManager(String.valueOf(userSession.getId()));
      int[] arrayOfInt1;
      int j = (arrayOfInt1 = itemlist).length;
      for (int i = 0; i < j; i++)
      {
        Integer fileId = Integer.valueOf(arrayOfInt1[i]);
        wf = this.workflowFileManager.getWorkflowFile(fileId);
        if ((wf == null) || 
          (!StrUtils.getIsExistIDs(havePermFlowIds, String.valueOf(wf.getWorkflow().getParentId())))) {
          createPermException(request, "流程归档->归档", null);
        } else if (!this.workflowFileManager.getCanToArchive(fromType, wf)) {
          createPermException(request, "流程归档->归档", "流程未结束！或者已归档");
        }
      }
      StringBuilder sb = new StringBuilder("-1");
      for (int i : itemlist) {
        sb.append("," + i);
      }
      Object map = new HashMap();
      ((Map)map).put("id_i_in", sb.toString());
      
      PageSortModel psm = new PageSortModel(request, "ec");
      workflowFiles = this.workflowFileManager
        .findWorkflowFileByPage((Map)map, psm);
      workflowArchive = new WorkflowArchive();
    }
    switch (type)
    {
    case 0: 
      for (WorkflowFile workflowFile : (List)workflowFiles)
      {
        if ("knowledge".equals(fromType))
        {
          if (workflowFile.getArchive().intValue() == 0) {
            workflowFile.setArchive(Integer.valueOf(1));
          } else {
            workflowFile.setArchive(Integer.valueOf(5));
          }
        }
        else if (workflowFile.getArchive().intValue() == 0) {
          workflowFile.setArchive(Integer.valueOf(2));
        } else {
          workflowFile.setArchive(Integer.valueOf(5));
        }
        this.workflowFileManager.saveWorkflowFile(workflowFile);
      }
      break;
    case 1: 
      String knowledgeId = ServletRequestUtils.getStringParameter(request, 
        "otherKnowledgeId", "-1");
      if (knowledgeId.equals("-1"))
      {
        saveMessage(request, 
        
          getMessage(request, "WorkflowFileManagerController_label27", "未能获取知识中心ID号，请重新选择！"));
        return mav;
      }
      workflowArchive.setKnowledgeTransForm(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransForm", "1"));
      workflowArchive.setKnowledgeTransFlowInfo(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransFormInfo", "1"));
      workflowArchive.setKnowledgeTransDoc(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransDoc", "2"));
      workflowArchive.setKnowledgeTransAttach(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransAttach", "1"));
      workflowArchive.setKnowledgeTarget(knowledgeId);
      workflowArchive.setKnowledgeFlowFormURL("http://127.0.0.1:" + 
        request.getLocalPort() + 
        request.getContextPath() + 
        "/workflowArchive.do");
      workflowArchive.setKnowledgefield(ServletRequestUtils.getStringParameter(
        request, "knowledgefield", "0"));
      if ("1".equals(ServletRequestUtils.getStringParameter(request, "knowledgefield", "0")))
      {
        String flowFieldstr = ServletRequestUtils.getStringParameter(request, "flowFieldName", "");
        String klgFieldstr = ServletRequestUtils.getStringParameter(request, "klgFieldName", "");
        if ((!"".equals(flowFieldstr)) && (!"".equals(klgFieldstr)))
        {
          String[] flowFields = flowFieldstr.substring(1).split(",");
          String[] klgFields = klgFieldstr.substring(1).split(",");
          List<WorkflowArchive.FlowToKnowledgeField> ftks = new ArrayList();
          for (int i = 0; i < flowFields.length; i++)
          {
            WorkflowArchive.FlowToKnowledgeField fa = new WorkflowArchive.FlowToKnowledgeField();
            fa.setKnowledgeFieldName(klgFields[i].substring(0, klgFields[i].indexOf("_")));
            fa.setWorkFlowFieldName(flowFields[i].substring(0, flowFields[i].indexOf("_")));
            ftks.add(fa);
          }
          workflowArchive.setFlowToKnowledge(ftks);
        }
      }
      int flag = this.toArchiveAdapter.workFlowToKnowledge((List)workflowFiles, 
        workflowArchive, this.userManager.getUser(userSession.getId()));
      if (flag == 0) {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label28", "已成功将 【") + 
          ((List)workflowFiles).size() + 
          getMessage(request, 
          "WorkflowFileManagerController_label29", 
          "】件办结公文归入知识中心！"));
      } else {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label28", "已成功将【") + (
          ((List)workflowFiles).size() - flag) + 
          getMessage(request, 
          "WorkflowFileManagerController_label30", 
          "】件公文归档到知识中心，其中 【") + 
          flag + 
          getMessage(request, 
          "WorkflowFileManagerController_label31", 
          "】件已做归档的公文被忽略！"));
      }
      break;
    case 2: 
      String archiveId = ServletRequestUtils.getStringParameter(request, 
        "otherKnowledgeId", "-1");
      if (archiveId.equals("-1"))
      {
        saveMessage(request, 
        
          getMessage(request, "WorkflowFileManagerController_label32", "未能获取档案门类ID号，请重新选择！"));
        return mav;
      }
      workflowArchive.setArchiveTransForm(
        ServletRequestUtils.getStringParameter(request, "knowledgeTransForm", "1"));
      workflowArchive.setArchiveTransFlowInfo(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransFormInfo", "1"));
      workflowArchive.setArchiveTransDoc(
        ServletRequestUtils.getStringParameter(request, "knowledgeTransDoc", "2"));
      workflowArchive.setArchiveTransAttach(ServletRequestUtils.getStringParameter(
        request, "knowledgeTransAttach", "1"));
      workflowArchive.setArchiveTarget(archiveId);
      workflowArchive.setArchiveFlowFormURL("http://127.0.0.1:" + 
        request.getLocalPort() + 
        request.getContextPath() + 
        "/workflowArchive.do");
      workflowArchive.setKnowledgefield(ServletRequestUtils.getStringParameter(
        request, "knowledgefield", "0"));
      int flag1 = this.toArchiveAdapter.workFlowToArchive((List)workflowFiles, 
        workflowArchive);
      if (flag1 == 0) {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label28", "已成功将 【") + 
          ((List)workflowFiles).size() + 
          getMessage(request, 
          "WorkflowFileManagerController_label33", 
          "】件办结公文归入档案系统！"));
      } else {
        saveMessage(request, 
          getMessage(request, "WorkflowFileManagerController_label28", "已成功将【") + (
          ((List)workflowFiles).size() - flag1) + 
          getMessage(request, 
          "WorkflowFileManagerController_label34", 
          "】件公文归档到档案系统，其中 【") + 
          flag1 + 
          getMessage(request, 
          "WorkflowFileManagerController_label31", 
          "】件已做归档的公文被忽略！"));
      }
      break;
    default: 
      break;saveMessage(request, 
        getMessage(request, "workflowController_label4", "请选择需不归档的流程文件数据！"));
      mav
        .setViewName("redirect:/modules/workflow/workflowFile.do?method=toArchive");
    }
    return mav;
  }
  
  public ModelAndView getMenusInfo(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    ModelAndView mav = new ModelAndView();
    mav.setViewName("/modules/workflow/workflowMenuListTree.jsp");
    List<Workflow> list = this.workflowManager.findmyWorkflowFlowfavor(user);
    
    int i = 2;
    
    List listss = new ArrayList();
    for (Workflow workflow : list)
    {
      workflow.setPos(Integer.valueOf(i));
      if (workflow.getSupervisors() != null)
      {
        String supervisors = workflow.getSupervisors();
        supervisors = supervisors.replaceAll(" ", "");
        String[] observer = supervisors.split(",");
        for (int h = 0; h < observer.length; h++) {
          if (String.valueOf(user.getId()).equals(observer[h])) {
            workflow.setSupervisors("YES");
          }
        }
      }
      listss.add(workflow);
      i++;
    }
    String workflowCatalogys = this.dictManager.findDictByLabel(
      "workflow.catalogy").getOptions();
    String[] catalogys = workflowCatalogys.split("/");
    Map filter = new HashMap();
    List returnWorkflow = new ArrayList();
    int pos = -100;
    




    List<String> listClause = new LinkedList();
    
    StringBuffer sbHql = new StringBuffer("select wf from Workflow wf where (");
    int count = 0;
    for (String string : catalogys) {
      if (!string.equals("费用报销"))
      {
        if (count++ > 0) {
          sbHql.append(" or ");
        }
        sbHql.append(" wf.catalogy=?");
        listClause.add(string);
      }
    }
    if (count == 0) {
      sbHql.append(" 1=2 ");
    }
    sbHql.append(") ");
    



    List<Workflow> workflowList = this.workflowManager.findWorkflowByHql(sbHql.toString(), count == 0 ? null : listClause.toArray(), user);
    if ((workflowList != null) && (workflowList.size() > 0))
    {
      Object map = new HashMap();
      for (??? = workflowList.iterator(); ((Iterator)???).hasNext();)
      {
        Workflow workflow2 = (Workflow)((Iterator)???).next();
        String catalogy = workflow2.getCatalogy();
        if ((StringUtils.isNotEmpty(catalogy)) && 
          (!((Map)map).containsKey(catalogy)))
        {
          Workflow workflow = new Workflow();
          workflow.setName(catalogy);
          workflow.setPos(Integer.valueOf(pos));
          workflow.setId(Integer.valueOf(0));
          workflow.setCatalogy("0");
          returnWorkflow.add(workflow);
          ((Map)map).put(catalogy, Integer.valueOf(pos));
          pos++;
        }
        int pos2 = ((Map)map).get(catalogy) == null ? pos : Integer.valueOf(((Map)map).get(catalogy).toString()).intValue();
        workflow2.setCatalogy(pos2);
        workflow2.setPos(Integer.valueOf(i));
        if (workflow2.getSupervisors() != null)
        {
          String supervisors = workflow2.getSupervisors();
          supervisors = supervisors.replaceAll(" ", "");
          String[] observer = supervisors.split(",");
          for (int j = 0; j < observer.length; j++) {
            if (String.valueOf(user.getId()).equals(observer[j])) {
              workflow2.setSupervisors("YES");
            }
          }
        }
        returnWorkflow.add(workflow2);
        i++;
      }
    }
    mav.addObject("workflowFavors", listss);
    mav.addObject("workflowList", returnWorkflow);
    return mav;
  }
  
  public ModelAndView getWorkflows(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflow_agentTree.jsp");
    Map map = WebUtils.getParametersStartingWith(request, "search_");
    UserSession user = (UserSession)request.getSession().getAttribute(
      org.springside.core.Constants.USER_IN_SESSION);
    

    mav.addObject("workflowTrees", this.workflowManager.findWorkflow(map, user));
    
    String ucIds = null;
    if (org.springside.core.Constants.SEPARATION_OF_POWERS)
    {
      List<Dept> depts = this.userAreaManager.getUserAreaForUser(user.getId());
      ucIds = ReflectUtil.joinCollectionAttributeForId(depts);
    }
    int i = 1;
    
    String workflowCatalogys = this.dictManager.findDictByLabel("workflow.catalogy").getOptions();
    String[] catalogys = workflowCatalogys.split("/");
    Map filter = new HashMap();
    List returnWorkflow = new ArrayList();
    int pos = -100;
    for (String string : catalogys)
    {
      Workflow workflow = new Workflow();
      workflow.setName(string);
      workflow.setPos(Integer.valueOf(pos));
      workflow.setId(Integer.valueOf(0));
      workflow.setCatalogy("0");
      filter.put("catalogy_s_eq", string);
      filter.put("status_i_eq", "1");
      if (org.springside.core.Constants.SEPARATION_OF_POWERS) {
        filter.put("deptXXucXXid_i_in", ucIds);
      }
      List<Workflow> workflowList = this.workflowManager.findWorkflow(filter);
      if ((workflowList != null) && (workflowList.size() > 0))
      {
        returnWorkflow.add(workflow);
        for (Workflow workflow2 : workflowList)
        {
          workflow2.setCatalogy(pos);
          workflow2.setPos(Integer.valueOf(i));
          returnWorkflow.add(workflow2);
          i++;
        }
        pos++;
      }
    }
    mav.addObject("workflowList", returnWorkflow);
    return mav;
  }
  
  public ModelAndView getWorkFlowListForTree(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView();
    

    String more = request.getParameter("more");
    if (StringUtils.isBlank(more)) {
      mav.setViewName("/modules/workflow/workflowlisttree.jsp");
    } else {
      mav.setViewName("/modules/workflow/workflowlisttree_x.jsp");
    }
    String workflowCatalogys = this.dictManager.findDictByLabel(
      "workflow.catalogy").getOptions();
    String[] catalogys = workflowCatalogys.split("/");
    Map filter = new HashMap();
    Map order = new LinkedHashMap();
    order.put("pos", "asc");
    List returnWorkflow = new ArrayList();
    int pos = -100;
    int i = 3;
    for (String string : catalogys)
    {
      Workflow workflow = new Workflow();
      workflow.setName(string);
      workflow.setPos(Integer.valueOf(pos));
      workflow.setId(Integer.valueOf(0));
      workflow.setCatalogy("0");
      filter.put("catalogy_s_eq", string);
      filter.put("ver_i_eq", "1");
      List<Workflow> workflowList = this.workflowManager.findWorkflow(filter, 
        "", order);
      if ((workflowList != null) && (workflowList.size() > 0))
      {
        returnWorkflow.add(workflow);
        for (Workflow workflow2 : workflowList)
        {
          workflow2.setCatalogy(pos);
          workflow2.setPos(Integer.valueOf(i));
          returnWorkflow.add(workflow2);
          i++;
        }
        pos++;
      }
    }
    mav.addObject("workflowList", returnWorkflow);
    return mav;
  }
  
  public ModelAndView ajaxCompareNowDate(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    response.setContentType("text/plain;charset=UTF-8");
    Writer writer = response.getWriter();
    
    Date nowDate = new Date();
    














    String stepdate = request.getParameter("stepdate");
    String compareDate = request.getParameter("compareDate");
    
    String flag = request.getParameter("flag");
    
    String id = request.getParameter("id");
    try
    {
      if ("file".equals(flag))
      {
        Map filter = new HashMap();
        filter.put("workflowFileXXid_i_eq", id);
        
        filter.put("issent_i_in", "1,2");
        List<WorkflowFileinbox> workflowFileinboxList = this.workflowFileinboxManager
          .findWorkflowFileinbox(filter);
        for (WorkflowFileinbox box : workflowFileinboxList) {
          if ((box.getWorkflowStep().getDays() != null) && 
            (box.getWorkflowStep().getDays().intValue() != 0))
          {
            int internal = box.getWorkflowStep().getDays().intValue() * 60;
            
            Date termDate = this.systemWorkhourManager.getBusinessTime(
              box.getUser(), box.getStartdate(), Integer.valueOf(internal));
            if (nowDate.compareTo(termDate) > 0)
            {
              writer.write("true");
              writer.close();
              return null;
            }
          }
          else if ((box.getWishdate() != null) && 
            (nowDate.compareTo(box.getWishdate()) > 0))
          {
            writer.write("true");
            writer.close();
            return null;
          }
        }
      }
      else if ("inbox".equals(flag))
      {
        WorkflowFileinbox inbox = this.workflowFileinboxManager
          .getWorkflowFileinbox(new Integer(id));
        if ((inbox.getIssent().intValue() != 1) && 
          (inbox.getIssent().intValue() != 2))
        {
          writer.write("false");
          writer.close();
          return null;
        }
        if ((stepdate != null) && (!"".equals(stepdate)) && 
          (!"0".equals(stepdate)))
        {
          int internal = Integer.parseInt(stepdate) * 60;
          
          Date termDate = this.systemWorkhourManager.getBusinessTime(
            inbox.getUser(), inbox.getStartdate(), Integer.valueOf(internal));
          if (nowDate.compareTo(termDate) > 0)
          {
            writer.write("true");
            writer.close();
            return null;
          }
        }
        else
        {
          if ((compareDate == null) || ("".equals(compareDate)))
          {
            writer.write("false");
            writer.close();
            return null;
          }
          SimpleDateFormat sd = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");
          
          Date newDate = sd.parse(compareDate);
          if (nowDate.compareTo(newDate) > 0)
          {
            writer.write("true");
            writer.close();
            return null;
          }
        }
      }
    }
    catch (Exception e)
    {
      writer.write("false");
      writer.close();
      return null;
    }
    writer.write("false");
    writer.close();
    return null;
  }
  
  public ModelAndView wordPrint(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ModelAndView mav = new ModelAndView("/modules/workflow/workflowFile_wordprint.jsp");
    UserSession user = getUserSession(request);
    String fileId = request.getParameter("workflowFileId");
    WorkflowFile workflowFile = this.workflowFileManager.getWorkflowFile(Integer.valueOf(fileId));
    Integer ParentflowId = workflowFile.getWorkflow().getParentId();
    if ((!this.workflowManager.getIsObservers(workflowFile.getWorkflow().getId(), user)) && 
      (!this.workflowManager.getIsSupervisor(workflowFile.getWorkflow().getId(), user)) && 
      (!this.workflowFileinboxManager.getIsWorkflowFileUser(user, String.valueOf(fileId)))) {
      if (!this.workflowFileManager.isArchiveMan(ParentflowId, user)) {
        if (!this.workflowFlowRightManager.getWorkflowPerm(workflowFile.getWorkflow().getId(), user.getId())) {
          createPermException(request, "协同审批->公文->word打印", null);
        }
      }
    }
    referenceData(request);
    return mav;
  }
  
  public void ajaxKnowledgeFields(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    Integer cid = Integer.valueOf(ServletRequestUtils.getIntParameter(request, "cid", 0));
    Writer writer = response.getWriter();
    if (cid.intValue() > 0)
    {
      List fields = this.workflowFileManager.getKnowledgeFields(this.knowledgeCatalogyManager.getKnowledgeCatalogy(cid));
      JSONArray jso = JSONArray.fromObject(fields);
      writer.write(jso.toString());
    }
    writer.close();
  }
  
  public void setWorkflowKnowledgeManager(WorkflowKnowledgeManager workflowKnowledgeManager)
  {
    this.workflowKnowledgeManager = workflowKnowledgeManager;
  }
  
  protected void onCreate(HttpServletRequest request, HttpServletResponse response, ModelAndView mav)
    throws Exception
  {}
}
